Canonicalize URLs when hashing sources
authorAlex Crichton <alex@alexcrichton.com>
Sat, 19 Jul 2014 05:38:30 +0000 (22:38 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sat, 19 Jul 2014 05:38:30 +0000 (22:38 -0700)
src/cargo/core/source.rs

index 6284f755ad8d2dae85471c2439f11ae21eba7100..cb479cd019781d60b0d1045f0c26a6b685e749f8 100644 (file)
@@ -1,5 +1,6 @@
 use std::fmt;
 use std::fmt::{Show, Formatter};
+use std::hash;
 use serialize::{Decodable, Decoder, Encodable, Encoder};
 
 use url::Url;
@@ -77,7 +78,7 @@ impl<E, S: Encoder<E>> Encodable<S, E> for Location {
     }
 }
 
-#[deriving(Encodable, Decodable, Clone, Eq, Hash)]
+#[deriving(Encodable, Decodable, Clone, Eq)]
 pub struct SourceId {
     pub kind: SourceKind,
     pub location: Location,
@@ -145,6 +146,24 @@ impl PartialEq for SourceId {
     }
 }
 
+impl<S: hash::Writer> hash::Hash<S> for SourceId {
+    fn hash(&self, into: &mut S) {
+        match *self {
+            SourceId {
+                kind: ref kind @ GitKind(..),
+                location: Remote(ref url)
+            } => {
+                kind.hash(into);
+                git::canonicalize_url(url.to_string().as_slice()).hash(into);
+            }
+            _ => {
+                self.kind.hash(into);
+                self.location.hash(into);
+            }
+        }
+    }
+}
+
 impl SourceId {
     pub fn new(kind: SourceKind, location: Location) -> SourceId {
         SourceId { kind: kind, location: location }